package hwf.control;

import java.io.File;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class MyConfig {
	
private boolean socksProxy=false;
private String ip;
private String port;
private String user;
private String password;
private String filepath;
private String address;
private String address2;
private String title;
private String body;
private String server;


public boolean getSocksProxy() {
	return socksProxy;
}


public String getIp() {
	return ip;
}


public String getPort() {
	return port;
}


public String getUser() {
	return user;
}


public String getPassword() {
	return password;
}


public String getFilepath() {
	return filepath;
}


public String getAddress() {
	return address;
}


public String getAddress2() {
	return address2;
}


public String getTitle() {
	return title;
}


public String getBody() {
	return body;
}


public String getServer() {
	return server;
}


public void getInfo(){
	try {
		   DocumentBuilderFactory factory = DocumentBuilderFactory
		     .newInstance();
		   DocumentBuilder builder = factory.newDocumentBuilder();
		   Document document = builder.parse(new File("mail_info.xml"));
		   Element rootElement = document.getDocumentElement();
          //读取数据库部分的信息
		   NodeList db_info = rootElement.getElementsByTagName("proxy");
		   Node element = (Element) db_info.item(0);
		 if("true".equalsIgnoreCase(element.getAttributes().getNamedItem("socksProxy").getNodeValue())){
		     this.socksProxy= true;
		                           }
		  this.ip=element.getAttributes().getNamedItem("ip").getNodeValue();
		  this.port=element.getAttributes().getNamedItem("port").getNodeValue();
		  //读取表的相关信息
		  NodeList table_info = rootElement.getElementsByTagName("mail");
		  Node tb_info = (Element) table_info.item(0);
		  this.user=tb_info.getAttributes().getNamedItem("user").getNodeValue();
		  this.password=tb_info.getAttributes().getNamedItem("pws").getNodeValue();
		  this.filepath=tb_info.getAttributes().getNamedItem("filepath").getNodeValue();
		  NodeList tb=tb_info.getChildNodes();
		  for (int j = 0; j < tb.getLength(); j++) {
			  Node detail = tb.item(j);
			  if("to".equals(detail.getNodeName())) {
				this.address=  detail.getTextContent();
			  }
			  if("cc".equals(detail.getNodeName())) {
				this.address2=  detail.getTextContent();
				  }			  
			  if("subject".equals(detail.getNodeName())) {
					this.title=  detail.getTextContent();
				  }
			  if("body".equals(detail.getNodeName())) {
					this.body=  detail.getTextContent();
				  }
			  if("smtp".equals(detail.getNodeName())) {
					this.server=  detail.getTextContent();
				  }
		  }
		   //System.out.println(this.mail);

		  } catch (Exception e) {
		   System.out.println("exception:" + e.getMessage());
		  }
}

}
